// pages/detail/show.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checked:false,
    tabIndex:0,
    detail:{},
    items:[],
  }
  ,
  checkboxChange: function (e) {
    //console.log('test');
   var checked = !this.data.checked;
    this.setData({
      checked: checked
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id=options.id;
    var that =this;
    //查询详情
    wx.request({
      url: 'https://wuxiyundongweilai.com/api/product/' + id,
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
       //console.log(res.data.data)
       var detail= res.data.data;
       

        that.setData({
          detail: detail,
        })


        var items = [];
        //获取套餐详情
        for (var i = 0; i < that.data.detail.combos.length; i++) {

          wx.request({
            url: 'https://wuxiyundongweilai.com/api/combo/' + that.data.detail.combos[i].id,
            header: {
              'content-type': 'application/json'
            },
            success: function (res2) {

              // that.data.items.push({aa:'aa'});
              console.log(res2.data.data.items)

              items.push(res2.data.data);
              if (items.length == that.data.detail.combos.length)
              {
                   that.setData({
                     items: items
                   })
              }

            }
          })
        }


       //获取套餐详情
      
      }
    })

   

  
  },
  contact: function (e) {
    wx.makePhoneCall({
      phoneNumber: '15380030139',
    })
  },
  onSendRequest:function(e)
  {
    var that =this;
    console.log(that.data.checked);
    if (!that.data.checked)
    {
     
        wx.showToast({
          title: '必须同意保险条款',
          icon: 'loading',
          duration: 1000
        })
        return false;

    }

  },

  onShowTab:function(e)
  {
   // console.log(e)
    var index=e.currentTarget.dataset.id;
    this.setData({
      tabIndex:index,
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})